/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Asterix21;

/**
 *
 * @author Yudis
 */
public class CAsterix21 {

    short[] m_shData;  //tipe short : 16 bit twos complement
    short[] m_shFSPEC;
    int m_iLength;
    int m_iIndex;
    //FRN1
    public short m_shSAC, m_shSIC;
    //FRN2
    public short m_shDCR, m_shGBS, m_shSIM, m_shTST, m_shRAB, m_shSAA, m_shSPI, m_shATP, m_shARC;
    //FRN3 Time of Day
    public String m_sTimeOfDay;
    //FRN4 Location in nWGS
    public float m_fLatitudeInWGS, m_fLongitudeInWGS;
    //FRN5
    public String  m_strTargetAddress, m_strCountry;
    //FRN6
    public String m_sGeometricAltitude;
    //FRN7
    public short m_shAC, m_shMN, m_shDC, m_shPA;
    //FRN8 Link technology
    public short m_shOTR, m_shVDL, m_shUAT, m_shMDS, m_shDTI;
    //FRN9=>Roll Angle => Twos Complement => 2 short
    public float m_fRollAngle;
    //==FRN10=>Flight Level => TWos Complement => 2 short
    public float m_fFlightLevel;
    //==FRN11=>Air Speed
    public float m_fAirSpeed;
    //==FRN12=>True Air Speed
    public int m_iTrueAirSpeed;
    //==FRN13=>Magnetic Heading
    public float m_fMagneticHeading;
    //==FRN14=>Barometric Vertical Rate
    public float m_fBarometricVerticalRate;
    //==FRN15=>Geometric Vertical Rate
    public float m_fGeometricVerticalRate;
    //==FRN16=>Ground Vector
    public float m_fGroundSpeed,  m_fTrackAngle;
    //==FRN17=>Rate of Turn
    public int m_iRateOfTurn;
    public short m_shTI;
    //==FRN18=>Target Identification
    public String m_sTargetID;
    //FRN19 => Velocity Accuracy => 1 short
    public int m_iVelocityAccuracy;
    //FRN20 => Time Of Day Accurasi => 1 short
    public int m_iTimeofDayAccuracy;
    //FRN21 => Target Status => 1 short
    public int m_iTargetStatus;
    //FRN22 => Emitter Category
    public int m_iEmitterCategory;
    //==FRN23=>Meteorology report
    int m_iWindSpeed,  m_iWindDirection, m_iTurbulance;
    float m_fTemperature;
    //==FRN24=>Intermediate State Selected Altitude
    public int m_iAltitude;
    public short m_shSource, m_shSAS;
    //==FRN25=>Final State Selected Altitude
    public short m_shMV, m_shAH, m_shAM;
    //==FRN26=>Trajectory Intent
    public short m_shREP, m_shTCPNumber, m_shTCA, m_shNC;
    public int  m_iLatitudeWgs84, m_iLongitudeWgs84, m_iTOV;
    public float m_fTTR ;
    public short m_shPointType, m_shTD, m_shTRA, m_shTOA;
    //==FRN27=>Mode 3/A Code in Octal Representation
    //==FRN28=>Signal Amplitude

    public CAsterix21() {
        int i;
        m_shData = new short[2048];
        m_shFSPEC = new short[8];
        m_iLength = 0;
        m_iIndex = 0;
        for(i=0; i<2048; i++)m_shData[i]=0;
    }

    public boolean ProsesDataAsterix21() {
        int x, i, len;

        if (m_shData[0] != (short)21) {
            return false;
        }
        len = HitungLength();
        if (m_iLength != len) {  //m_Length sdh diisi pada IsiData()
            return false;
        }

        for (x = 0; x < 8; x++) {
            m_shFSPEC[x] = (short)0; //initialize
        }
        x = 0;
        m_iIndex = 3; //FSPEC mulai dari index=3
        while ((m_shData[m_iIndex] & 0x0001) == 1) {
            m_shFSPEC[x++] = m_shData[m_iIndex++];
        }
        m_shFSPEC[x] = m_shData[m_iIndex++]; //masukkan FSPEC yng terakhir
        //System.out.printf("FSpec: ");
        //for(i=0; i<=x; i++) System.out.printf("%x ", m_shFSPEC[i]);
        //System.out.println();
        //Cek Frn
        //Data Source Identification
        if (GetFRN1()) {
            frn1();
        }
        //Target Report Descriptor
        if (GetFRN2()) {
            frn2();
        }

        //Time of day
        if (GetFRN3()) {
            frn3();
        }
        //Position in WGS
        if (GetFRN4()) {
            frn4();
        }

        //Target Address
        if (GetFRN5()) {
            frn5();
        }

        //Geometric Altitude
        if (GetFRN6()) {
            frn6();
        }

        //Figure of Merit
        if (GetFRN7()) {
            frn7();
        }

        //Link technology
        if (GetFRN8()) {
            frn8();
        }

        //FRN9=>Roll Angle => Twos Complement => 2 short
        if (GetFRN9()){
            frn9();
        }

        //==FRN10=>Flight Level => TWos Complement => 2 short
        if(GetFRN10()){
            frn10();
        }

        //==FRN11=>Air Speed
        if(GetFRN11()){
            frn11();
        }

        //==FRN12=>True Air Speed
        if(GetFRN12()){
            frn12();
        }

        //==FRN13=>Magnetic Heading
        if(GetFRN13()){
            frn13();
        }

        //==FRN14=>Barometric Vertical Rate
        if(GetFRN14()){
            frn14();
        }

        //==FRN15=>Geometric Vertical Rate
        if(GetFRN15()){
            frn15();
        }

        //==FRN16=>Ground Vector
        if(GetFRN16()){
            frn16();
        }

        //==FRN17=>Rate of Turn
        if(GetFRN17()){
            frn17();
        }

        //==FRN18=>Target Identification
        if(GetFRN18()){
            frn18();
        }

        //FRN19 => Velocity Accuracy => 1 short
        if(GetFRN19()){
            frn19();
        }

        //FRN20 => Time Of Day Accurasi => 1 short
        if(GetFRN20()){
            frn20();
        }

        //FRN21 => Target Status => 1 short
        if(GetFRN21()){
            frn21();
        }

        //FRN22 => Emitter Category
        if(GetFRN22()){
            frn22();
        }

        //==FRN23=>Meteorology report
        if(GetFRN23()){
            frn23();
        }

        //==FRN24=>Intermediate State Selected Altitude
        if(GetFRN24()){
            frn24();
        }

        //==FRN25=>Final State Selected Altitude
        if(GetFRN25()){
            frn25();
        }

        //==FRN26=>Trajectory Intent
        if(GetFRN26()){
            frn26();
        }

        //==FRN27=>Mode 3/A Code in Octal Representation
        if(GetFRN27()){
            frn27();
        }

        //==FRN28=>Signal Amplitude
        if(GetFRN28()){
            frn28();
        }

        return true;
    }

    //==FRN28=>Signal Amplitude
    private void frn28(){
        short octet;
        octet = m_shData[m_iIndex++];
        //System.out.printf("FRN28:\n");
    }

    //==FRN27=>Mode 3/A Code in Octal Representation
    private void frn27(){
        short octetHigh, octetMid, octetLow;
        octetHigh = m_shData[m_iIndex++];          //1
        octetLow = m_shData[m_iIndex++];           //2
        //System.out.printf("FRN27:\n");
    }

    //==FRN26=>Trajectory Intent
    private void frn26(){
        short octet, FX, FXext1, TIS, TID;
        short octetHigh, octetMid, octetLow;
        do{
            octet = m_shData[m_iIndex++];
            FX = (short)(octet & 0x0001);
            TIS = (short)((octet & 0x0080) >> 7);
            TID = (short)((octet & 0x0040) >> 6);
	    if(TIS != 0){
                do{
                    octet = m_shData[m_iIndex++];
                    FXext1 = (short)(octet & 0x0001);
		}while(FXext1 != 0);
                //System.out.printf("FRN26:\n");
            }
            if(TID != 0){
                m_shREP = m_shData[m_iIndex++];          //1
                octet = m_shData[m_iIndex++];            //2
                m_shTCPNumber = (short)(octet & 0x003F);
                m_shTCA = (short)((octet & 0x0080) >> 7);
                m_shNC  = (short)((octet & 0x0040) >> 6);
		octetHigh = m_shData[m_iIndex++];        //3
                octetLow  = m_shData[m_iIndex++];        //4
		m_iAltitude = 256 *octetHigh + octetLow;

		octetHigh = m_shData[m_iIndex++];        //5
		octetMid  = m_shData[m_iIndex++];        //6
		octetLow  = m_shData[m_iIndex++];        //7
	        m_iLatitudeWgs84 = 65536 * octetHigh + 256 * octetMid + octetLow;

		octetHigh = m_shData[m_iIndex++];        //8
                octetMid  = m_shData[m_iIndex++];        //9
		octetLow  = m_shData[m_iIndex++];        //10
		m_iLongitudeWgs84 = 65536 * octetHigh + 256 * octetMid + octetLow;

		octet = m_shData[m_iIndex++];            //11
                m_shPointType = (short)(octet & 0x00F0);
                m_shTD = (short)((octet & 0x000C) >> 2);
                m_shTRA = (short)((octet & 0x0002) >> 1);
                m_shTOA = (short)(octet & 0x0001);
		octetHigh = m_shData[m_iIndex++];       //12
		octetMid = m_shData[m_iIndex++];        //13
		octetLow = m_shData[m_iIndex++];        //14
                m_iTOV = 65536 * octetHigh + 256 * octetMid + octetLow;
	        octetHigh = m_shData[m_iIndex++];       //15
		octetLow  = m_shData[m_iIndex++];       //16
                m_fTTR = (float)((256 * octetHigh + octetLow)*0.01);
                //System.out.printf("FRN26:\n");
            }
        }while (FX != 0);
    }

    //==FRN25=>Final State Selected Altitude
    private void frn25(){
        short alt, octetHigh, octetLow;
	octetHigh = m_shData[m_iIndex++];
	octetLow  = m_shData[m_iIndex++];
        alt = (short)(octetHigh & 0x001F);
        m_iAltitude = 256 * alt + octetLow;
	m_shMV = (short)((octetHigh & 0x0080) >> 7);
	m_shAH = (short)((octetHigh & 0x0040) >> 6);
	m_shAM = (short)((octetHigh & 0x0020) >> 5);
        //System.out.printf("FRN25:\n");
    }

    //==FRN24=>Intermediate State Selected Altitude
    private void frn24(){
        short alt, octetHigh, octetLow;
	octetHigh = m_shData[m_iIndex++];
	octetLow  = m_shData[m_iIndex++];
        alt = (short)(octetHigh & 0x001F);
	m_iAltitude = 256 * alt + octetLow;
	m_shSource = (short)((octetHigh & 0x0060) >> 5);
	m_shSAS = (short)((octetHigh & 0x0080) >> 7);
        //System.out.printf("FRN24: Altitude=%d, Source=%d, SAS=%d\n", m_iAltitude, m_shSource, m_shSAS);
    }

    //==FRN23=>Meteorology report
    private void frn23(){
        short octet, octetHigh, octetLow;
        short WS,WD,TMP,TRB,FX;
        do{
            octet = m_shData[m_iIndex++];
            FX  = (short)(octet & 0x0001);
            TRB = (short)((octet & 0x0010) >> 4);
            TMP = (short)((octet & 0x0020) >> 5);
            WD  = (short)((octet & 0x0040) >> 6);
            WS  = (short)((octet & 0x0080) >> 7);

            //Field-1
	    if(WS != 0){
                octetHigh = m_shData[m_iIndex++];
		octetLow  = m_shData[m_iIndex++];
		m_iWindSpeed = 256 * octetHigh + octetLow;
                //System.out.printf("FRN23: WindSpeed=%d\n", m_iWindSpeed);
            }

            //Field-2
            if(WD != 0){
		octetHigh = m_shData[m_iIndex++];
		octetLow  = m_shData[m_iIndex++];
                m_iWindDirection = 256 * octetHigh + octetLow;
                //System.out.printf("FRN23: WindDirection=%d\n", m_iWindDirection);
            }

            //Field-3
            if(TMP != 0){
		octetHigh = m_shData[m_iIndex++];
		octetLow  = m_shData[m_iIndex++];
		m_fTemperature = (float)((256 * octetHigh + octetLow) * 0.25);
                //System.out.printf("FRN23: Temperature=%d\n", m_fTemperature);
            }

            //Field-4
            if(TRB != 0){
		octetHigh = m_shData[m_iIndex++];
		octetLow  = m_shData[m_iIndex++];
		m_iTurbulance = 256 * octetHigh + octetLow;
                //System.out.printf("FRN23: Turbulance=%d\n",m_iTurbulance);
            }

        }while(FX != 0);
    }

    //FRN22 => Emitter Category
    private void frn22(){
        m_iEmitterCategory = m_shData[m_iIndex++];
        //System.out.printf("FRN22: EmitterCategory=%d\n",m_iEmitterCategory);
    }

    //FRN21 => Target Status => 1 short
    private void frn21(){
        m_iTargetStatus=m_shData[m_iIndex++];
        //System.out.printf("FRN21: TargetStatus=%d\n",m_iTargetStatus);
    }

    //FRN20 => Time Of Day Accurasi => 1 short
    private void frn20(){
        m_iTimeofDayAccuracy=m_shData[m_iIndex++]/256;
        //System.out.printf("FRN20: TimeofDayAccuracy=%d\n",m_iTimeofDayAccuracy);
    }

    //FRN19 => Velocity Accuracy => 1 short
    private void frn19(){
        m_iVelocityAccuracy = m_shData[m_iIndex++];
        //System.out.printf("FRN19: VelocityAccuracy=%d\n", m_iVelocityAccuracy);
    }

    //==FRN18=>Target Identification
    private void frn18(){
        char ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8;
        short octet1,octet2,octet3;
        short x,y;
        octet1 = m_shData[m_iIndex++];
        octet2 = m_shData[m_iIndex++];
        octet3 = m_shData[m_iIndex++];
        ch1 = (char)(octet1 >> 2);
        if((ch1 >= 0x01) && ( ch1 <= 0x1A)) ch1 = (char)(ch1 + 64);
        x = (short)(octet1 & 0x0003);
        y = (short)((octet2 & 0x00F0) >> 4);
        ch2 = (char)(x*16 + y);
        if((ch2 >= 0x01) && ( ch2 <= 0x1A)) ch2 = (char)(ch2 + 64);
        x = (short)(octet2 & 0x000F);
        y = (short)((octet3 & 0x00C0) >> 6);
        ch3 = (char)(x*4 + y);
        if((ch3 >= 0x01) && ( ch3 <= 0x1A)) ch3 = (char)(ch3 + 64);
        ch4 = (char)(octet3 & 0x003F);
        if((ch4 >= 0x01) && ( ch4 <= 0x1A)) ch4 = (char)(ch4 + 64);

        octet1 = m_shData[m_iIndex++];
        octet2 = m_shData[m_iIndex++];
        octet3 = m_shData[m_iIndex++];
        ch5 = (char)(octet1 >> 2);
        if((ch5 >= 0x01) && ( ch5 <= 0x1A)) ch5 = (char)(ch5 + 64);
        x = (short)(octet1 & 0x0003);
        y = (short)((octet2 & 0x00F0) >> 4);
        ch6 = (char)(x*16 + y);
        if((ch6 >= 0x01) && ( ch6 <= 0x1A)) ch6 = (char)(ch6 + 64);
        x = (short)(octet2 & 0x000F);
        y = (short)((octet3 & 0x00C0) >> 6);
        ch7 = (char)(x*4 + y);
        if((ch7 >= 0x01) && ( ch7 <= 0x1A)) ch7 = (char)(ch7 + 64);
        ch8 = (char)(octet3 & 0x003F);
        if((ch8 >= 0x01) && ( ch8 <= 0x1A)) ch8 = (char)(ch8 + 64);

        m_sTargetID = String.format("%c%c%c%c%c%c%c%c",ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8);
        //System.out.printf("FRN18: TargetID=%s\n",m_sTargetID);
    }

    //==FRN17=>Rate of Turn
    private void frn17(){
        short octet, FX;
        octet = m_shData[m_iIndex++];
        FX = (short)(octet & 0x0001);
        m_shTI = (short)((octet & 0x00C0) >> 6);
	if(FX > 0){
		octet = m_shData[m_iIndex++];
                FX = (short)(octet & 0x0001);
		while(FX > 0){
                    octet = m_shData[m_iIndex++];
                    FX = (short)(octet & 0x0001);
                    m_iRateOfTurn = (int)(octet >> 1);
                    //System.out.printf("FRN17: RateOfTurn=%d\n",m_iRateOfTurn);
                }
	}
    }

    //==FRN16=>Ground Vector
    private void frn16(){
        short octetHigh, octetLow;
        octetHigh = m_shData[m_iIndex++];
        octetLow = m_shData[m_iIndex++];
        if((octetHigh & 0x0080) != 0){
            //Nilai negatif
            m_fGroundSpeed = octetHigh & 0x007F;
            m_fGroundSpeed = octetHigh * 256 + octetLow;
            m_fGroundSpeed = m_fGroundSpeed - 32768;
        }else{
             m_fGroundSpeed = octetHigh * 256 + octetLow;
        }
        m_fGroundSpeed = (float)(m_fGroundSpeed * 0.2197); //satuan kt

        //Track Angle => biasa bukan twos komplement => 2 short
        octetHigh = m_shData[m_iIndex++];
        octetLow = m_shData[m_iIndex++];
        m_fTrackAngle = 256 * octetHigh + octetLow;
        m_fTrackAngle = (float)(m_fTrackAngle * 0.0055); //(360/pow(2,16));
        //System.out.printf("FRN16: GroundSpeed=%f, TrackAngle=%f\n",m_fGroundSpeed, m_fTrackAngle);
    }

    //==FRN15=>Geometric Vertical Rate
    private void frn15(){
        short octetHigh, octetLow;
        octetHigh = m_shData[m_iIndex++];
        octetLow = m_shData[m_iIndex++];
        if((octetHigh & 0x0080) != 0){
            //Nilai negatif
            m_fGeometricVerticalRate = octetHigh & 0x007F;
            m_fGeometricVerticalRate = m_fGeometricVerticalRate * 256 + octetLow;
            m_fGeometricVerticalRate = m_fGeometricVerticalRate - 32768;
        }else{
             m_fGeometricVerticalRate = octetHigh * 256 + octetLow;
        }
        m_fGeometricVerticalRate = (float)(m_fGeometricVerticalRate * 6.25);
        //System.out.printf("FRN15: GeometricVerticalRate=%f\n",m_fGeometricVerticalRate);
    }

    //==FRN14=>Barometric Vertical Rate  => twos complement tapi 2 short
    private void frn14(){
        short octetHigh, octetLow;
        octetHigh = m_shData[m_iIndex++];
        octetLow = m_shData[m_iIndex++];
        if((octetHigh & 0x0080) != 0){
            //Nilai negatif
            m_fBarometricVerticalRate = octetHigh & 0x007F;
            m_fBarometricVerticalRate = m_fBarometricVerticalRate * 256 + octetLow;
            m_fBarometricVerticalRate = m_fBarometricVerticalRate - 32768;
        }else{
             m_fBarometricVerticalRate = octetHigh * 256 + octetLow;
        }
        m_fBarometricVerticalRate = (float)(m_fBarometricVerticalRate * 6.25);
        //System.out.printf("FRN14: BarometricVerticalrate=%f\n",m_fBarometricVerticalRate);
    }

    //==FRN13=>Magnetic Heading
    private void frn13(){
        short octetHigh, octetLow;
        octetHigh = m_shData[m_iIndex++];
        octetLow = m_shData[m_iIndex++];
        m_fMagneticHeading = 256 * octetHigh + octetLow;
        m_fMagneticHeading = (float)(m_fMagneticHeading * 0.0055);
        //System.out.printf("FRN13: MagneticHeading=%f\n",m_fMagneticHeading);
    }

    //==FRN12=>True Air Speed
    private void frn12(){
        short octetHigh, octetLow;
        octetHigh = m_shData[m_iIndex++];
        octetLow = m_shData[m_iIndex++];
        m_iTrueAirSpeed = 256 * octetHigh + octetLow;
        //System.out.printf("FRN12: TrueAirSpeed=%d\n",m_iTrueAirSpeed);
    }

    //==FRN11=>Air Speed
    private void frn11(){
        short octetHigh, octetLow;
        short sevenbitHigh;
        short IM;
        octetHigh = m_shData[m_iIndex++];
        octetLow = m_shData[m_iIndex++];
        IM = (short)(octetHigh & 0x0080); //1 bit
        IM = (short)(IM >> 7);
        sevenbitHigh = (short)(octetHigh & 0x007F);
        m_fAirSpeed = sevenbitHigh * 256 + octetLow;
        if(IM > 0) m_fAirSpeed=(float)(m_fAirSpeed*0.001);
	else m_fAirSpeed=(float)(m_fAirSpeed / Math.pow(2.0, -14));
        //System.out.printf("FRN11: AirSpeed=%f\n",m_fAirSpeed);
    }

    //==FRN10=>Flight Level => TWos Complement => 2 short
    private void frn10(){
        short octetHigh, octetLow;
        octetHigh = m_shData[m_iIndex++];
        octetLow = m_shData[m_iIndex++];
        if((octetHigh & 0x0080) != 0){
            //Nilai negatif
            m_fFlightLevel = octetHigh & 0x007F;
            m_fFlightLevel = m_fFlightLevel * 256 + octetLow;
            m_fFlightLevel = m_fFlightLevel - 32768;
        }else{
             m_fFlightLevel = octetHigh * 256 + octetLow;
        }
        m_fFlightLevel = m_fFlightLevel / 4; //bobot LSB
        //System.out.printf("FRN10: FlightLevel=%d\n",m_iFlightLevel);
    }

    //FRN9=>Roll Angle => Twos Complement => 2 short
    private void frn9(){
        short octetHigh, octetLow;
        octetHigh = m_shData[m_iIndex++];
        octetLow = m_shData[m_iIndex++];
        if((octetHigh & 0x0080) != 0){
            //Nilai negatif
            m_fRollAngle = octetHigh & 0x007F;
            m_fRollAngle = m_fRollAngle * 256 + octetLow;
            m_fRollAngle = m_fRollAngle - 32768;
        }else{
            m_fRollAngle = octetHigh * 256 + octetLow;
        }
        m_fRollAngle = (float)(m_fRollAngle * 0.01); //bobot LSB = 0.01
        //System.out.printf("FRN9: RollAngle=%d\n",m_iRollAngle);
    }

    //Link technology
    private void frn8(){
        short x = m_shData[m_iIndex++];
        m_shOTR = (short)(x & 0x0001);
        m_shVDL = (short)((x & 0x0002) >> 1);
        m_shUAT = (short)((x & 0x0004) >> 2);
        m_shMDS = (short)((x & 0x0008) >> 3);
        m_shDTI = (short)((x & 0x0010) >> 4);
        //System.out.printf("FRN8: OTR=%d, VDL=%d, UAT=%d, MDS=%d, DTI=%d\n",m_shOTR, m_shVDL, m_shUAT, m_shMDS, m_shDTI);
    }

    //Figure of Merit
    private void frn7(){
        int x;
        short octetHigh, octetLow;
        octetHigh = m_shData[m_iIndex++];
	octetLow  = m_shData[m_iIndex++];
        x = 256 * octetHigh + octetLow;
        m_shPA = (short)(x & 0x000F);  //4bit 3-0
        m_shDC = (short)((x & 0x0C00) >> 10);  //2bit 11-10
        m_shMN = (short)((x & 0x3000) >> 12);  //2but 13-12
        m_shAC = (short)((x & 0xC000) >> 14);  //2bit 15-14
        //System.out.printf("FRN7: PA=%d, DC=%d, MN=%d, AC=%d\n", m_shPA, m_shDC, m_shMN, m_shAC);

    }

    //Geometric Altitude
    private void frn6(){
        short octetHigh, octetLow;
	double altitude;
	octetHigh=m_shData[m_iIndex++];
	octetLow=m_shData[m_iIndex++];
	if((octetHigh & 0x0080) != 0){   //Twos Complement => negatip
            octetHigh = (short)(octetHigh & 0x007F); //MSB di NOL kan
            altitude = 256 * octetHigh + octetLow;
            altitude = altitude - 32768;
	}else{
	    altitude = 256 * octetHigh + octetLow;
	}
	altitude = altitude * 6.25;
	m_sGeometricAltitude = String.format("%f",altitude);
        //System.out.printf("FRN6: GeometricAltitude=%s\n", m_sGeometricAltitude);
    }

    //Target Address
    private void frn5() {
        boolean b;
        int i,TargetAddress;
        String ss;
        short octet1 = m_shData[m_iIndex++];
        short octet2 = m_shData[m_iIndex++];
        short octet3 = m_shData[m_iIndex++];
        TargetAddress = 65536 * octet1 + 256 * octet2 + octet3;
        b=AmbilCountry1(TargetAddress);
	if(b==false) b=AmbilCountry2(TargetAddress);
        else if(b==false) b=AmbilCountry3(TargetAddress);
        else if(b==false) b=AmbilCountry4(TargetAddress);
        ss = String.format("%x",TargetAddress);
	ss = ss.toUpperCase();
        m_strTargetAddress=String.format("%s", ss);
        //System.out.printf("FRN5: TargetAddress=%s, Country=%s\n", m_strTargetAddress,m_strCountry);
        //System.out.printf("FRN5: %x %x %x\n",octet1,octet2,octet3);
    }

    //Position in WGS
    private void frn4() {
        short octet1 = m_shData[m_iIndex++]; //two's complement
        short octet2 = m_shData[m_iIndex++];
        short octet3 = m_shData[m_iIndex++];
        short octet4 = m_shData[m_iIndex++];
        if((octet1 & 0x0080) > 0){  //negatip
            m_fLatitudeInWGS = (float) (16777216 * (octet1 & 0x007F) + 65536 * octet2 + 256 * octet3 + octet4);
            m_fLatitudeInWGS = m_fLatitudeInWGS - (float)2147483648.0;
        }else{  //positip
            m_fLatitudeInWGS = (float) (16777216 * (octet1 & 0x007F) + 65536 * octet2 + 256 * octet3 + octet4);
        }
        m_fLatitudeInWGS = (float) ((m_fLatitudeInWGS * 180) / Math.pow(2.0, 25.0));
        //System.out.printf("FRN4: %x %x %x %x ",octet1,octet2,octet3,octet4);

        octet1 = m_shData[m_iIndex++]; //two's complement
        octet2 = m_shData[m_iIndex++];
        octet3 = m_shData[m_iIndex++];
        octet4 = m_shData[m_iIndex++];
        if((octet1 & 0x0080) > 0){ //negatip
            m_fLongitudeInWGS = (float) (16777216 * (octet1 & 0x007F) + 65536 * octet2 + 256 * octet3 + octet4);
            m_fLongitudeInWGS = m_fLongitudeInWGS - (float)2147483648.0;
        }else{
            m_fLongitudeInWGS = (float) (16777216 * (octet1 & 0x007F) + 65536 * octet2 + 256 * octet3 + octet4);
        }
        m_fLongitudeInWGS = (float) ((m_fLongitudeInWGS * 180) / Math.pow(2.0, 25.0));
        //System.out.printf("%x %x %x %x\n",octet1,octet2,octet3,octet4);
        //System.out.printf("FRN4: LatitudeWGS=%f, LongitudeWGS=%f\n", m_fLatitudeInWGS,m_fLongitudeInWGS);
    }

    //Time of daya => 3 short
    private void frn3() {
        int octet1 = m_shData[m_iIndex++];
        int octet2 = m_shData[m_iIndex++];
        int octet3 = m_shData[m_iIndex++];
        long sec;
        int hour, minute, second;
        int sisajam, sisamenit;
        sec = 65536 * octet1 + 256 * octet2 + octet3;
        sec = sec / 128; //bobot LSB
        hour = (int)(sec / 3600);
        sisajam = (int)(sec % 3600);
        minute = sisajam / 60;
        sisamenit = sisajam % 60;
        second = sisamenit % 60;
        m_sTimeOfDay = String.format("%d:%d:%d", hour, minute, second);
        System.out.printf("FRN3: TimeOfDay=%s\n", m_sTimeOfDay);
        //System.out.printf("FRN3: %x %x %x\n",octet1,octet2,octet3);
    }

    private void frn2() {
        short octet1 = m_shData[m_iIndex++];
        short octet2 = m_shData[m_iIndex++];
        m_shDCR = (short) ((octet1 & 0x0080) >> 7);
        m_shGBS = (short) ((octet1 & 0x0040) >> 6);
        m_shSIM = (short) ((octet1 & 0x0020) >> 5);
        m_shTST = (short) ((octet1 & 0x0010) >> 4);
        m_shRAB = (short) ((octet1 & 0x0008) >> 3);
        m_shSAA = (short) ((octet1 & 0x0004) >> 2);
        m_shSPI = (short) ((octet1 & 0x0002) >> 1);
        m_shATP = (short) ((octet2 & 0x00E0) >> 5);
        m_shARC = (short) ((octet2 & 0x0018) >> 3);
        //System.out.printf("FRN2: DCR=%d, GBS=%d, SIM=%d, TST=%d, RAB=%d, SAA=%d, SPI=%d, ATP=%d, ARC=%d\n",m_DCR,m_GBS,m_SIM,m_TST,m_RAB,m_SAA,m_SPI,m_ATP,m_ARC);
        //System.out.printf("FRN2: %x %x\n",octet1,octet2);
    }

    private void frn1() {
        m_shSAC = m_shData[m_iIndex++];
        m_shSIC = m_shData[m_iIndex++];
        //System.out.printf("FRN1: SAC=%d, SIC=%d\n",m_SAC,m_SIC);
        //System.out.printf("FRN1: %x %x\n",m_shSAC,m_shSIC);
    }

    private boolean GetFRN1() {
        if ((m_shFSPEC[0] & 0x0080) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN2() {
        if ((m_shFSPEC[0] & 0x0040) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN3() {
        if ((m_shFSPEC[0] & 0x0020) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN4() {
        if ((m_shFSPEC[0] & 0x0010) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN5() {
        if ((m_shFSPEC[0] & 0x0008) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN6() {
        if ((m_shFSPEC[0] & 0x0004) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN7() {
        if ((m_shFSPEC[0] & 0x0002) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFX1() {
        if ((m_shFSPEC[0] & 0x0001) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN8() {
        if ((m_shFSPEC[1] & 0x0080) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN9() {
        if ((m_shFSPEC[1] & 0x0040) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN10() {
        if ((m_shFSPEC[1] & 0x0020) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN11() {
        if ((m_shFSPEC[1] & 0x0010) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN12() {
        if ((m_shFSPEC[1] & 0x0008) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN13() {
        if ((m_shFSPEC[1] & 0x0004) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN14() {
        if ((m_shFSPEC[1] & 0x0002) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFX2() {
        if ((m_shFSPEC[1] & 0x0001) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN15() {
        if ((m_shFSPEC[2] & 0x0080) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN16() {
        if ((m_shFSPEC[2] & 0x0040) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN17() {
        if ((m_shFSPEC[2] & 0x0020) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN18() {
        if ((m_shFSPEC[2] & 0x0010) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN19() {
        if ((m_shFSPEC[2] & 0x0008) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN20() {
        if ((m_shFSPEC[2] & 0x0004) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN21() {
        if ((m_shFSPEC[2] & 0x0002) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFX3() {
        if ((m_shFSPEC[2] & 0x0001) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN22() {
        if ((m_shFSPEC[3] & 0x0080) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN23() {
        if ((m_shFSPEC[3] & 0x0040) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN24() {
        if ((m_shFSPEC[3] & 0x0020) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN25() {
        if ((m_shFSPEC[3] & 0x0010) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN26() {
        if ((m_shFSPEC[3] & 0x0008) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN27() {
        if ((m_shFSPEC[3] & 0x0004) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN28() {
        if ((m_shFSPEC[3] & 0x0002) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFX4() {
        if ((m_shFSPEC[3] & 0x0001) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN29() {
        if ((m_shFSPEC[4] & 0x0080) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN30() {
        if ((m_shFSPEC[4] & 0x0040) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN31() {
        if ((m_shFSPEC[4] & 0x0020) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN32() {
        if ((m_shFSPEC[4] & 0x0010) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN33() {
        if ((m_shFSPEC[4] & 0x0008) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN34() {
        if ((m_shFSPEC[4] & 0x0004) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN35() {
        if ((m_shFSPEC[4] & 0x0002) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFX5() {
        if ((m_shFSPEC[4] & 0x0001) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN36() {
        if ((m_shFSPEC[5] & 0x0080) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN37() {
        if ((m_shFSPEC[5] & 0x0040) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN38() {
        if ((m_shFSPEC[5] & 0x0020) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN39() {
        if ((m_shFSPEC[5] & 0x0010) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN40() {
        if ((m_shFSPEC[5] & 0x0008) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN41() {
        if ((m_shFSPEC[5] & 0x0004) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN42() {
        if ((m_shFSPEC[5] & 0x0002) == 1) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFX6() {
        if ((m_shFSPEC[5] & 0x0001) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN43() {
        if ((m_shFSPEC[6] & 0x0080) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN44() {
        if ((m_shFSPEC[6] & 0x0040) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN45() {
        if ((m_shFSPEC[6] & 0x0020) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN46() {
        if ((m_shFSPEC[6] & 0x0010) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN47() {
        if ((m_shFSPEC[6] & 0x0008) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN48() {
        if ((m_shFSPEC[6] & 0x0004) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFRN49() {
        if ((m_shFSPEC[6] & 0x0002) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private boolean GetFX7() {
        if ((m_shFSPEC[6] & 0x0001) > 0) {
            return true;
        } else {
            return false;
        }
    }

    private int HitungLength() {
        int length;
        length = 256 * m_shData[1] + m_shData[2];
        return length;
    }

    public void IsiData(short[] Data, int len) {
        int i;
        for (i = 0; i < len; i++) {
            m_shData[i] = Data[i];
            //System.out.printf("%x ",(byte)m_shData[i]);
        }
        m_iLength = len;
        //System.out.println("");
    }

    private boolean AmbilCountry1(int target) {
        m_strCountry = "";
        if ((target & 0xFFF000) == 0x700000) {
            m_strCountry = String.format("%s","Afghanistan"); // 0 1 1 1 0 0 0 0 0 0 0 0
        } else if ((target & 0xFFFC00) == 0x501000) {
            m_strCountry = "Albania"; // 0 1 0 1 0 0 0 0 0 0 0 1 0 0
        } else if ((target & 0xFF8000) == 0x0A0000) {
            m_strCountry = "Algeria"; // 0 0 0 0 1 0 1 0 0
        } else if ((target & 0xFFF000) == 0x09000) {
            m_strCountry = "Angola"; // 0 0 0 0 1 0 0 1 0 0 0 0
        } else if ((target & 0xFFFC00) == 0x0CA00) {
            m_strCountry = "Antigua and Barbuda"; // 0 0 0 0 1 1 0 0 1 0 1 0 0 0
        } else if ((target & 0xFC0000) == 0xE0000) {
            m_strCountry = "Argentina"; // 1 1 1 0 0 0
        } else if ((target & 0xFFFC00) == 0x60000) {
            m_strCountry = "Armenia"; // 0 1 1 0 0 0 0 0 0 0 0 0 0 0
        } else if ((target & 0xFC0000) == 0x7C0000) {
            m_strCountry = "Australia"; // 0 1 1 1 1 1
        } else if ((target & 0xFF8000) == 0x440000) {
            m_strCountry = "Austria"; // 0 1 0 0 0 1 0 0 0
        } else if ((target & 0xFFFC00) == 0x600800) {
            m_strCountry = "Azerbaijan"; // 0 1 1 0 0 0 0 0 0 0 0 0 1 0
        } else if ((target & 0xFFF000) == 0x0A8000) {
            m_strCountry = "Bahamas"; // 0 0 0 0 1 0 1 0 1 0 0 0
        } else if ((target & 0xFFF000) == 0x894000) {
            m_strCountry = "Bahrain"; // 1 0 0 0 1 0 0 1 0 1 0 0
        } else if ((target & 0xFFF000) == 0x702000) {
            m_strCountry = "Bangladesh"; // 0 1 1 1 0 0 0 0 0 0 1 0
        } else if ((target & 0xFFFC00) == 0x0AA000) {
            m_strCountry = "Barbados"; // 0 0 0 0 1 0 1 0 1 0 1 0 0 0
        } else if ((target & 0xFFFC00) == 0x510000) {
            m_strCountry = "Belarus"; // 0 1 0 1 0 0 0 1 0 0 0 0 0 0
        } else if ((target & 0xFF8000) == 0x448000) {
            m_strCountry = "Belgium"; // 0 1 0 0 0 1 0 0 1
        } else if ((target & 0xFFFC00) == 0x0AB000) {
            m_strCountry = "Belize"; // 0 0 0 0 1 0 1 0 1 0 1 1 0 0
        } else if ((target & 0xFFFC00) == 0x094000) {
            m_strCountry = "Benin"; // 0 0 0 0 1 0 0 1 0 1 0 0 0 0
        } else if ((target & 0xFFFC00) == 0x680000) {
            m_strCountry = "Bhutan"; // 0 1 1 0 1 0 0 0 0 0 0 0 0 0
        } else if ((target & 0xFFF000) == 0xE94000) {
            m_strCountry = "Bolivia"; // 1 1 1 0 1 0 0 1 0 1 0 0
        } else if ((target & 0xFFFC00) == 0x513000) {
            m_strCountry = "Bosnia and Herzegovina"; // 0 1 0 1 0 0 0 1 0 0 1 1 0 0
        } else if ((target & 0xFFFC00) == 0x030000) {
            m_strCountry = "Botswana"; // 0 0 0 0 0 0 1 1 0 0 0 0 0 0
        } else if ((target & 0xFC0000) == 0xE20000) {
            m_strCountry = "Brazil"; // 1 1 1 0 0 1
        } else if ((target & 0xFFFC00) == 0x895000) {
            m_strCountry = "Brunai Darussalam"; // 1 0 0 0 1 0 0 1 0 1 0 1 0 0
        } else if ((target & 0xFF8000) == 0x450000) {
            m_strCountry = "Bulgaria"; // 0 1 0 0 0 1 0 1 0
        } else if ((target & 0xFFF000) == 0x09C000) {
            m_strCountry = "Burkina Faso"; // 0 0 0 0 1 0 0 1 1 1 0 0
        } else if ((target & 0xFFF000) == 0x032000) {
            m_strCountry = "Burundi"; // 0 0 0 0 0 0 1 1 0 0 1 0
        } else if ((target & 0xFFF000) == 0x70E000) {
            m_strCountry = "Cambodia"; // 0 1 1 1 0 0 0 0 1 1 1 0
        } else if ((target & 0xFFF000) == 0x034000) {
            m_strCountry = "Cameroon"; // 0 0 0 0 0 0 1 1 0 1 0 0
        } else if ((target & 0xFC0000) == 0xC00000) {
            m_strCountry = "Canada"; // 1 1 0 0 0 0
        } else if ((target & 0xFFFC00) == 0x096000) {
            m_strCountry = "Cape Verde"; // 0 0 0 0 1 0 0 1 0 1 1 0 0 0
        } else if ((target & 0xFFF000) == 0x06C000) {
            m_strCountry = "Central African Republic"; // 0 0 0 0 0 1 1 0 1 1 0 0
        } else if ((target & 0xFFF000) == 0x084000) {
            m_strCountry = "Chad"; // 0 0 0 0 1 0 0 0 0 1 0 0
        } else if ((target & 0xFFF000) == 0xE80000) {
            m_strCountry = "Chile"; // 1 1 1 0 1 0 0 0 0 0 0 0
        } else if ((target & 0xFC0000) == 0x780000) {
            m_strCountry = "China"; // 0 1 1 1 1 0
        } else if ((target & 0xFFF000) == 0x0AC000) {
            m_strCountry = "Colombia"; // 0 0 0 0 1 0 1 0 1 1 0 0
        } else if ((target & 0xFFFC00) == 0x035000) {
            m_strCountry = "Comoros"; // 0 0 0 0 0 0 1 1 0 1 0 1 0 0
        } else if ((target & 0xFFF000) == 0x036000) {
            m_strCountry = "Congo"; // 0 0 0 0 0 0 1 1 0 1 1 0
        } else if ((target & 0xFFFC00) == 0x901000) {
            m_strCountry = "Cook Islands"; // 1 0 0 1 0 0 0 0 0 0 0 1 0 0
        } else if ((target & 0xFFF000) == 0x0AE000) {
            m_strCountry = "Costa Rica"; // 0 0 0 0 1 0 1 0 1 1 1 0
        } else if ((target & 0xFFF000) == 0x038000) {
            m_strCountry = "Côte d Ivoire"; // 0 0 0 0 0 0 1 1 1 0 0 0
        } else if ((target & 0xFFFC00) == 0x501C00) {
            m_strCountry = "Croatia"; // 0 1 0 1 0 0 0 0 0 0 0 1 1 1
        } else if ((target & 0xFFF000) == 0x0B0000) {
            m_strCountry = "Cuba"; // 0 0 0 0 1 0 1 1 0 0 0 0
        } else if ((target & 0xFFFC00) == 0x4C8000) {
            m_strCountry = "Cyprus"; // 0 1 0 0 1 1 0 0 1 0 0 0 0 0
        } else if ((target & 0xFF8000) == 0x458000) {
            m_strCountry = "Czech Republic"; // 0 1 0 0 1 0 0 1 1
        } else if ((target & 0xFF8000) == 0x720000) {
            m_strCountry = "Democratic People's Republic of Korea"; // 0 1 1 1 0 0 1 0 0
        } else if ((target & 0xFFF000) == 0x08C000) {
            m_strCountry = "Democratic Republic of the Congo"; // 0 0 0 0 1 0 0 0 1 1 0 0
        } else if ((target & 0xFF8000) == 0x458000) {
            m_strCountry = "Denmark"; // 0 1 0 0 0 1 0 1 1
        } else if ((target & 0xFFFC00) == 0x098000) {
            m_strCountry = "Djibouti"; // 0 0 0 0 1 0 0 1 1 0 0 0 0 0
        } else if ((target & 0xFFF000) == 0x0C4000) {
            m_strCountry = "Dominican Republic"; // 0 0 0 0 1 1 0 0 0 1 0 0
        }
        if (m_strCountry.isEmpty()) {
            return false;
        } else {
            return true;
        }
    }

     private boolean AmbilCountry2(int target) {
        m_strCountry = "";
        if ((target & 0xFFF000) == 0xE84000) {
            m_strCountry = "Ecuador"; // 1 1 1 0 1 0 0 0 0 1 0 0
        } else if ((target & 0xFF8000) == 0x010000) {
            m_strCountry = "Egypt"; // 0 0 0 0 0 0 0 1 0
        } else if ((target & 0xFFF000) == 0x0B2000) {
            m_strCountry = "El Salvador"; // 0 0 0 0 1 0 1 1 0 0 1 0
        } else if ((target & 0xFFF000) == 0x042000) {
            m_strCountry = "Equatorial Guinea"; // 0 0 0 0 0 1 0 0 0 0 1 0
        } else if ((target & 0xFFFC00) == 0x202000) {
            m_strCountry = "Eritrea"; // 0 0 1 0 0 0 0 0 0 0 1 0 0 0
        } else if ((target & 0xFFFC00) == 0x511000) {
            m_strCountry = "Estonia"; // 0 1 0 1 0 0 0 1 0 0 0 1 0 0
        } else if ((target & 0xFFF000) == 0x040000) {
            m_strCountry = "Ethiopia"; // 0 0 0 0 0 1 0 0 0 0 0 0
        } else if ((target & 0xFFF000) == 0xC88000) {
            m_strCountry = "Fiji"; // 1 1 0 0 1 0 0 0 1 0 0 0
        } else if ((target & 0xFF8000) == 0x460000) {
            m_strCountry = "Finland"; // 0 1 0 0 0 1 1 0 0
        } else if ((target & 0xFC0000) == 0x380000) {
            m_strCountry = "France"; //0 0 1 1 1 0
        } else if ((target & 0xFFF000) == 0x03E000) {
            m_strCountry = "Gabon"; // 0 0 0 0 0 0 1 1 1 1 1 0
        } else if ((target & 0xFFF000) == 0x09A000) {
            m_strCountry = "Gambia"; // 0 0 0 0 1 0 0 1 1 0 1 0
        } else if ((target & 0xFFFC00) == 0x512000) {
            m_strCountry = "Georgia"; // 0 1 0 1 0 0 0 1 0 1 0 0 0 0
        } else if ((target & 0xFC0000) == 0x3C0000) {
            m_strCountry = "Germany"; // 0 0 1 1 1 1
        } else if ((target & 0xFFF000) == 0x044000) {
            m_strCountry = "Ghana"; // 0 0 0 0 0 1 0 0 0 1 0 0
        } else if ((target & 0xFF8000) == 0x468000) {
            m_strCountry = "Greece"; // 0 1 0 0 0 1 1 0 1
        } else if ((target & 0xFFFC00) == 0x0CC000) {
            m_strCountry = "Grenada"; // 0 0 0 0 1 1 0 0 1 1 0 0 0 0
        } else if ((target & 0xFFF000) == 0x0B4000) {
            m_strCountry = "Guatemala"; // 0 0 0 0 1 0 1 1 0 1 0 0
        } else if ((target & 0xFFF000) == 0x046000) {
            m_strCountry = "Guinea"; // 0 0 0 0 0 1 0 0 0 1 1 0
        } else if ((target & 0xFFFC00) == 0x048000) {
            m_strCountry = "Guinea-Bissau"; // 0 0 0 0 0 1 0 0 1 0 0 0 0 0
        } else if ((target & 0xFFF000) == 0x0B6000) {
            m_strCountry = "Guyana"; // 0 0 0 0 1 0 1 1 0 1 1 0
        } else if ((target & 0xFFF000) == 0x0B8000) {
            m_strCountry = "Haiti"; // 0 0 0 0 1 0 1 1 1 0 0 0
        } else if ((target & 0xFFF000) == 0x0BA000) {
            m_strCountry = "Honduras"; // 0 0 0 0 1 0 1 1 1 0 1 0
        } else if ((target & 0xFF8000) == 0x470000) {
            m_strCountry = "Hungary"; // 0 1 0 0 0 1 1 1 0
        } else if ((target & 0xFFF000) == 0x4CC000) {
            m_strCountry = "Iceland"; // 0 1 0 0 1 1 0 0 1 1 0 0
        } else if ((target & 0xFC0000) == 0x800000) {
            m_strCountry = "India"; // 1 0 0 0 0 0
        } else if ((target & 0xFF8000) == 0x8A0000) {
            m_strCountry = "Indonesia"; // 1 0 0 0 1 0 1 0 0
        } else if ((target & 0xFF8000) == 0x730000) {
            m_strCountry = "Iran, Islamic Republic of"; //0 1 1 1 0 0 1 1 0
        } else if ((target & 0xFF8000) == 0x728000) {
            m_strCountry = "Iraq"; // 0 1 1 1 0 0 1 0 1
        } else if ((target & 0xFFF000) == 0x4CA000) {
            m_strCountry = "Ireland"; // 0 1 0 0 1 1 0 0 1 0 1 0
        } else if ((target & 0xFF8000) == 0x738000) {
            m_strCountry = "Israel"; // 0 1 1 1 0 0 1 1 1
        } else if ((target & 0xFC0000) == 0x300000) {
            m_strCountry = "Italy"; // 0 0 1 1 0 0
        } else if ((target & 0xFFF000) == 0x0BE000) {
            m_strCountry = "Jamaica"; // 0 0 0 0 1 0 1 1 1 1 1 0
        } else if ((target & 0xFC0000) == 0x820000) {
            m_strCountry = "Japan"; // 1 0 0 0 0 1
        } else if ((target & 0xFF8000) == 0x740000) {
            m_strCountry = "Jordan"; // 0 1 1 1 0 1 0 0 0
        } else if ((target & 0xFFFC00) == 0x683000) {
            m_strCountry = "Kazakhstan"; // 0 1 1 0 1 0 0 0 0 0 1 1 0 0
        } else if ((target & 0xFFF000) == 0x04C000) {
            m_strCountry = "Kenya"; // 0 0 0 0 0 1 0 0 1 1 0 0
        } else if ((target & 0xFFFC00) == 0xC8E000) {
            m_strCountry = "Kiribati"; // 1 1 0 0 1 0 0 0 1 1 1 0 0 0
        } else if ((target & 0xFFF000) == 0x706000) {
            m_strCountry = "Kuwait"; // 0 1 1 1 0 0 0 0 0 1 1 0
        } else if ((target & 0xFFFC00) == 0x601000) {
            m_strCountry = "Kyrgyzstan"; // 0 1 1 0 0 0 0 0 0 0 0 1 0 0
        } else if ((target & 0xFFF000) == 0x708000) {
            m_strCountry = "Lao People's Democratic Republic"; // 0 1 1 1 0 0 0 0 1 0 0 0
        } else if ((target & 0xFFFC00) == 0x502C00) {
            m_strCountry = "Latvia"; // 0 1 0 1 0 0 0 0 0 0 1 0 1 1
        } else if ((target & 0xFF8000) == 0x748000) {
            m_strCountry = "Lebanon"; // 0 1 1 1 0 1 0 0 1
        } else if ((target & 0xFFFC00) == 0x04A000) {
            m_strCountry = "Lesotho"; // 0 0 0 0 0 1 0 0 1 0 1 0 0 0
        } else if ((target & 0xFFF000) == 0x050000) {
            m_strCountry = "Liberia"; // 0 0 0 0 0 1 0 1 0 0 0 0
        } else if ((target & 0xFF8000) == 0x018000) {
            m_strCountry = "Libyan Arab Jamahiriya"; // 0 0 0 0 0 0 0 1 1
        } else if ((target & 0xFFFC00) == 0x503C00) {
            m_strCountry = "Lithuania"; // 0 1 0 1 0 0 0 0 0 0 1 1 1 1
        } else if ((target & 0xFFFC00) == 0x4D0000) {
            m_strCountry = "Luxembourg"; // 0 1 0 0 1 1 0 1 0 0 0 0 0 0
        }
        if (m_strCountry.isEmpty()) {
            return false;
        } else {
            return true;
        }
    }

     private boolean AmbilCountry3(int target) {
        m_strCountry = "";
       	if((target & 0xFFF000)==0x054000){
            m_strCountry ="Madagascar";  // 0 0 0 0 0 1 0 1 0 1 0 0
        }else if((target & 0xFFF000)==0x058000){
            m_strCountry = "Malawi";  // 0 0 0 0 0 1 0 1 1 0 0 0
        }else if((target & 0xFF8000)==0x750000){
            m_strCountry = "Malaysia"; // 0 1 1 1 0 1 0 1 0
        }else if((target & 0xFFFC00)==0x05A000){
            m_strCountry = "Maldives"; // 0 0 0 0 0 1 0 1 1 0 1 0 0 0
        }else if((target & 0xFFF000)==0x05C000){
            m_strCountry = "Mali"; // 0 0 0 0 0 1 0 1 1 1 0 0
        }else if((target & 0xFFFC00)==0x4D2000){
            m_strCountry = "Malta"; // 0 1 0 0 1 1 0 1 0 0 1 0 0 0
        }else if((target & 0xFFFC00)==0x900000){
            m_strCountry = "Marshall Islands"; // 1 0 0 1 0 0 0 0 0 0 0 0 0 0
        }else if((target & 0xFFFC00)==0x05E000){
            m_strCountry = "Mauritania"; // 0 0 0 0 0 1 0 1 1 1 1 0 0 0
        }else if((target & 0xFFFC00)==0x060000){
            m_strCountry = "Mauritius"; // 0 0 0 0 0 1 1 0 0 0 0 0 0 0
        }else if((target & 0xFF8000)==0x0D0000){
            m_strCountry = "Mexico"; // 0 0 0 0 1 1 0 1 0
        }else if((target & 0xFFFC00)==0x681000){
            m_strCountry = "Micronesia, Federated States of"; // 0 1 1 0 1 0 0 0 0 0 0 1 0 0
        }else if((target & 0xFFFC00)==0x4D4000){
            m_strCountry = "Monaco"; // 0 1 0 0 1 1 0 1 0 1 0 0 0 0
        }else if((target & 0xFFFC00)==0x682000) {
            m_strCountry = "Mongolia"; // 0 1 1 0 1 0 0 0 0 0 1 0 0 0
        }else if((target & 0xFF8000)==0x020000){
            m_strCountry = "Morocco"; // 0 0 0 0 0 0 1 0 0
        }else if((target & 0xFFF000)==0x006000){
            m_strCountry = "Mozambique";  // 0 0 0 0 0 0 0 0 0 1 1 0
        }else if((target & 0xFFF000)==0x704000){
            m_strCountry = "Myanmar"; // 0 1 1 1 0 0 0 0 0 1 0 0
        }else if((target & 0xFFFC00)==0x201000){
            m_strCountry="Namibia"; // 0 0 1 0 0 0 0 0 0 0 0 1 0 0
        }else if((target & 0xFFFC00)==0xC8A000){
            m_strCountry="Nauru"; // 1 1 0 0 1 0 0 0 1 0 1 0 0 0
        } else if((target & 0xFFF000)==0x70A000){
            m_strCountry="Nepal"; // 0 1 1 1 0 0 0 0 1 0 1 0
        } else if((target & 0xFF8000)==0x480000){
            m_strCountry = "Netherlands, Kingdom of the"; // 0 1 0 0 1 0 0 0 0
        } else if((target & 0xC80000)==0x750000){
            m_strCountry = "New Zealand"; // 1 1 0 0 1 0 0 0 0
        } else if((target & 0xFFF000)==0x0C0000){
            m_strCountry = "Nicaragua"; // 0 0 0 0 1 1 0 0 0 0 0 0
        } else if((target & 0xFF8000)==0x750000){
            m_strCountry = "Niger"; // 0 0 0 0 0 1 1 0 0 0 1 0
        } else if((target & 0xFFF000)==0x064000){
            m_strCountry = "Nigeria"; // 0 0 0 0 0 1 1 0 0 1 0 0
        } else if((target & 0xFF8000)==0x478000){
            m_strCountry = "Norway";  // 0 1 0 0 0 1 1 1 1
        } else if((target & 0xFFFC00)==0x70C000){
            m_strCountry = "Oman"; // 0 1 1 1 0 0 0 0 1 1 0 0 0
        } else if((target & 0xFF8000)==0x760000){
            m_strCountry = "Pakistan"; // 0 1 1 1 0 1 1 0 0
        } else if((target & 0xFFFC00)==0x684000){
            m_strCountry = "Palau"; // 0 1 1 0 1 0 0 0 0 1 0 0 0 0
        } else if((target & 0xFFF000)==0x0C2000){
            m_strCountry = "Panama"; // 0 0 0 0 1 1 0 0 0 0 1 0
        } else if((target & 0xFFF000)==0x898000){
            m_strCountry = "Papua New Guinea"; // 1 0 0 0 1 0 0 1 1 0 0 0
        } else if((target & 0xFFF000)==0xE88000){
            m_strCountry = "Paraguay"; // 1 1 1 0 1 0 0 0 1 0 0 0
        } else if((target & 0xFFF000)==0xE8C000){
            m_strCountry = "Peru"; // 1 1 1 0 1 0 0 0 1 1 0 0
        } else if((target & 0xFF8000)==0x758000){
            m_strCountry = "Philippines"; // 0 1 1 1 0 1 0 1 1
        } else if((target & 0xFF8000)==0x488000){
            m_strCountry = "Poland"; // 0 1 0 0 1 0 0 0 1
        } else if((target & 0xFF8000)==0x490000){
            m_strCountry = "Portugal"; // 0 1 0 0 1 0 0 1 0
        } else if((target & 0xFFFC00)==0x06A000){
            m_strCountry = "Qatar"; //0 0 0 0 0 1 1 0 1 0 1 0 0 0
        } else if((target & 0xFF8000)==0x718000){
            m_strCountry = "Republic of Korea"; //0 1 1 1 0 0 0 1 1
        } else if((target & 0xFFFC00)==0x504C00){
            m_strCountry = "Republic of Moldova"; // 0 1 0 1 0 0 0 0 0 1 0 0 1 1
        } else if((target & 0xFF8000)==0x4A0000){
            m_strCountry = "Romania"; // 0 1 0 0 1 0 1 0 0
        } else if((target & 0xF00000)==0x100000){
            m_strCountry = "Russian Federation"; //0 0 0 1
        } else if((target & 0xFFF000)==0x06E000){
            m_strCountry = "Rwanda"; //0 0 0 0 0 1 1 0 1 1 1 0
        }

        if (m_strCountry.isEmpty()) {
            return false;
        } else {
            return true;
        }
     }

     private boolean AmbilCountry4(int target) {
        m_strCountry = "";
        if((target & 0xFFFC00)==0xC8C000) m_strCountry = "Saint Lucia"; //1 1 0 0 1 0 0 0 1 1 0 0 0 0
	else if((target & 0xFFFC00)==0x0BC000) m_strCountry = "Saint Vincent and the Grenadines"; //0 0 0 0 1 0 1 1 1 1 0 0 0 0
	else if((target & 0xFFFC00)==0x902000) m_strCountry = "Samoa"; //1 0 0 1 0 0 0 0 0 0 1 0 0 0
	else if((target & 0xFFFC00)==0x500000) m_strCountry = "San Marino"; //0 1 0 1 0 0 0 0 0 0 0 0 0 0
	else if((target & 0xFFFC00)==0x09E000) m_strCountry = "Sao Tome and Principe"; //0 0 0 0 1 0 0 1 1 1 1 0 0 0
	else if((target & 0xFF8000)==0x710000) m_strCountry = "Saudi Arabia"; //0 1 1 1 0 0 0 1 0
	else if((target & 0xFFF000)==0x070000) m_strCountry = "Senegal"; //0 0 0 0 0 1 1 1 0 0 0 0
	else if((target & 0xFFFC00)==0x074000) m_strCountry = "Seychelles"; //0 0 0 0 0 1 1 1 0 1 0 0 0 0
	else if((target & 0xFFFC00)==0x076000) m_strCountry = "Sierra Leone"; //0 0 0 0 0 1 1 1 0 1 1 0 0 0
	else if((target & 0xFF8000)==0x768000) m_strCountry = "Singapore"; //0 1 1 1 0 1 1 0 1
	else if((target & 0xFFFC00)==0x505C00) m_strCountry = "Slovakia"; //0 1 0 1 0 0 0 0 0 1 0 1 1 1
	else if((target & 0xFFFC00)==0x506C00) m_strCountry = "Slovenia"; //0 1 0 1 0 0 0 0 0 1 1 0 1 1
	else if((target & 0xFFFC00)==0x897000) m_strCountry = "Solomon Islands"; //1 0 0 0 1 0 0 1 0 1 1 1 0 0
	else if((target & 0xFFF000)==0x078000) m_strCountry = "Somalia"; //0 0 0 0 0 1 1 1 1 0 0 0
	else if((target & 0xFF8000)==0x001000) m_strCountry = "South Africa"; //0 0 0 0 0 0 0 0 1
	else if((target & 0xFC0000)==0x340000) m_strCountry = "Spain"; //0 0 1 1 0 1
	else if((target & 0xFF8000)==0x770000) m_strCountry = "Sri Lanka"; //0 1 1 1 0 1 1 1 0
	else if((target & 0xFFF000)==0x07C000) m_strCountry = "Sudan"; //0 0 0 0 0 1 1 1 1 1 0 0
	else if((target & 0xFFF000)==0x0C8000) m_strCountry = "Suriname"; //0 0 0 0 1 1 0 0 1 0 0 0
	else if((target & 0xFFFC00)==0x07A000) m_strCountry = "Swaziland"; //0 0 0 0 0 1 1 1 1 0 1 0 0 0
	else if((target & 0xFF8000)==0x4A8000) m_strCountry = "Sweden"; //0 1 0 0 1 0 1 0 1
	else if((target & 0xFF8000)==0x4B0000) m_strCountry = "Switzerland"; //0 1 0 0 1 0 1 1 0
	else if((target & 0xFF8000)==0x778000) m_strCountry = "Syrian Arab Republic"; //0 1 1 1 0 1 1 1 1
	else if((target & 0xFFFC00)==0x515000) m_strCountry = "Tajikistan"; //0 1 0 1 0 0 0 1 0 1 0 1 0 0
	else if((target & 0xFF8000)==0x880000) m_strCountry = "Thailand"; //1 0 0 0 1 0 0 0 0
	else if((target & 0xFFFC00)==0x512000) m_strCountry = "The former Yugoslav Republic of Macedonia"; //0 1 0 1 0 0 0 1 0 0 1 0 0 0
	else if((target & 0xFFF000)==0x088000) m_strCountry = "Togo";//0 0 0 0 1 0 0 0 1 0 0 0
	else if((target & 0xFFFC00)==0xC8D000) m_strCountry = "Tonga"; //1 1 0 0 1 0 0 0 1 1 0 1 0 0
	else if((target & 0xFFF000)==0x0C6000) m_strCountry = "Trinidad and Tobago"; //0 0 0 0 1 1 0 0 0 1 1 0
	else if((target & 0xFF8000)==0x028000) m_strCountry = "Tunisia"; //0 0 0 0 0 0 1 0 1
	else if((target & 0xFF8000)==0x4B8000) m_strCountry = "Turkey"; //0 1 0 0 1 0 1 1 1
	else if((target & 0xFFFC00)==0x601800) m_strCountry = "Turkmenistan"; //0 1 1 0 0 0 0 0 0 0 0 1 1 0
	else if((target & 0xFFF000)==0x068000) m_strCountry = "Uganda"; //0 0 0 0 0 1 1 0 1 0 0 0
	else if((target & 0xFF8000)==0x508000) m_strCountry = "Ukraine"; //0 1 0 1 0 0 0 0 1
	else if((target & 0xFFF000)==0x896000) m_strCountry = "United Arab Emirates"; //1 0 0 0 1 0 0 1 0 1 1 0
	else if((target & 0xFC0000)==0x400000) m_strCountry = "United Kingdom"; //0 1 0 0 0 0
	else if((target & 0xFFF000)==0x080000) m_strCountry = "United Republic of Tanzania"; //0 0 0 0 1 0 0 0 0 0 0 0
	else if((target & 0xF00000)==0xA00000) m_strCountry = "United States"; //1 0 1 0
	else if((target & 0xFFF000)==0xE90000) m_strCountry = "Uruguay"; //1 1 1 0 1 0 0 1 0 0 0 0
	else if((target & 0xFFFC00)==0x507C00) m_strCountry = "Uzbekistan"; //0 1 0 1 0 0 0 0 0 1 1 1 1 1
	else if((target & 0xFFFC00)==0xC90000) m_strCountry = "Vanuatu"; //1 1 0 0 1 0 0 1 0 0 0 0 0 0
	else if((target & 0xFF8000)==0x0D8000) m_strCountry = "Venezuela"; //0 0 0 0 1 1 0 1 1
	else if((target & 0xFF8000)==0x888000) m_strCountry = "Viet Nam"; //1 0 0 0 1 0 0 0 1
	else if((target & 0xFFF000)==0x890000) m_strCountry = "Yemen"; //1 0 0 0 1 0 0 1 0 0 0 0
	else if((target & 0xFFF000)==0x08A000) m_strCountry = "Zambia"; //0 0 0 0 1 0 0 0 1 0 1 0
	else if((target & 0xFFFC00)==0x002000) m_strCountry = "Zimbabwe"; //0 0 0 0 0 0 0 0 0 1 0 0 0 0
	else if((target & 0xFF8000)==0x4C0000) m_strCountry = "Yugoslavia"; //0 1 0 0 1 1 0 0 0
        if (m_strCountry.isEmpty()) {
            return false;
        } else {
            return true;
        }
     }
}
